package dk.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ReturnData.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import dk.Service.TokenService;
import dk.beans.user;
import dk.mapper.*;

@RestController
@RequestMapping
public class LoginAPIController {
	@Autowired
	usermapper usermapper;
	@Autowired
	TokenService tokenservice;
	@RequestMapping("hello")
	public ResponseData hello () {
		return new ResponseData("hello",1,1);
	}
	@RequestMapping("GetTokenByNameAndPassword")
	public ResponseData login(String username,String password) {
		QueryWrapper<user> QueryWrapper = new QueryWrapper<user>();
		//去数据库中查询
		if(username!=null && password != null) {
			user user = usermapper.selectOne(QueryWrapper.eq("username",username));
			
			if(user.getUserpassword().equals(password) ) {
				//验证成功发放token
				ResponseData responseData = tokenservice.GetTokenByid(user.getId(),7);
				return responseData;
			}
			return new ResponseData("账号密码错误", 201, null);
		}
		else {
			return new ResponseData("参数错误", 201, null);
		}
		
	}
	

}
